<template>
  <d2-container>
    <div class="flex-1 mx-3 mt-2">
      <el-form :model="formData" ref="form" label-width="80px">
        <div>
          <el-form-item label="开启通告" prop="formData">
            <el-switch v-model="formData.is_show"></el-switch>
          </el-form-item>
        </div>
        <div class="mt-2">
          <el-input type="textarea" :rows="4" v-model="formData.content" placeholder="通告内容"></el-input>
        </div>
      </el-form>
      <div class="row-ac mt-2 font-s-2 text-muted">
        <div>发布时间</div>
        <div class="ml-2">{{ noticeDetail.update_time }}</div>
      </div>
      <div class="flex-1 row mt-5"><el-button type="primary" @click="submitForm">确 定</el-button>
      </div>
    </div>
  </d2-container>
</template>

<script>
  import {
    noticeUpdateUrl,
    noticeDetailUrl,
  } from "@/utils/interface"
  export default {
    data() {
      return {
        formData: {
          content: '',
          is_show: false
        },
        noticeDetail: ''
      }
    },
    created() {
      this.initData()
    },
    methods: {
      initData() {
        this.getNoticeDetail()
      },
      getNoticeDetail() {
        this.$get(noticeDetailUrl).then(res => {
          this.noticeDetail = res.data.data
          this.formData = {
            content: res.data.data.content,
            is_show: res.data.data.is_show,
          }
          console.log('555', this.noticeDetail);
        })
      },
      submitForm(){
        this.$put(noticeUpdateUrl, this.formData).then(res=>{
          console.log('852852', res);
          if(res.data.code == 200){
             this.$message.success('保存成功')
             this.getNoticeDetail()
          }
        })
      }
    }
  }
</script>

<style>
</style>
